package com.book.biz.impl;

import java.sql.SQLException;
import java.util.List;

import com.book.bean.Messagess;
import com.book.bean.PageVo;
import com.book.bean.Reply;
import com.book.biz.MessageBiz;
import com.book.dao.MessageDao;
import com.book.dao.impl.MessageDaoImpl;
import com.book.util.DBUtil;

public class MessageBizImpl implements MessageBiz {
	private MessageDao msgDao = new MessageDaoImpl();
	
	public MessageBizImpl() {
		super();
	}
	
	public MessageBizImpl(MessageDao msgDao) {
		super();
		this.msgDao = msgDao;
	}

	public MessageDao getMsgDao() {
		return msgDao;
	}

	public void setMsgDao(MessageDao msgDao) {
		this.msgDao = msgDao;
	}

	@Override
	public List<Messagess> listAllMsg() {
		try {
			return msgDao.listAllMsg();
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}finally{
			try {
				DBUtil.closeConn();
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		return null;
	}


	@Override
	public List<Messagess> listMyMsg(String uname) {
		try {
			return msgDao.listMyMsg(uname);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}finally{
			try {
				DBUtil.closeConn();
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		return null;
	}


	@Override
	public boolean addMessage(Messagess message) {
		try {
			return msgDao.addMessage(message);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}finally{
			try {
				DBUtil.closeConn();
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		return false;
	}


	@Override
	public boolean modifyMessage(int mid) {
		try {
			return msgDao.modifyMessage(mid);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}finally{
			try {
				DBUtil.closeConn();
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		return false;
	}


	@Override
	public boolean deleteMessage(int mid) {
		try {
			return msgDao.deleteMessage(mid);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}finally{
			try {
				DBUtil.closeConn();
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		return false;
	}


	@Override
	public Messagess listMsgById(int mid) {
		try {
			return msgDao.listMsgById(mid);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}finally{
			try {
				DBUtil.closeConn();
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		return null;
	}


	@Override
	public PageVo<Messagess> listMyMsg(int pageIndex, int pageSize, String uname) {
		try {
			return msgDao.listMyMsg(pageIndex, pageSize, uname);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}finally{
			try {
				DBUtil.closeConn();
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		return null;
	}

	@Override
	public PageVo<Messagess> listAllMsg(int pageIndex, int pageSize) {
		try {
			return msgDao.listAllMsg(pageIndex, pageSize);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}finally{
			try {
				DBUtil.closeConn();
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		return null;
	}

	@Override
	public Messagess getOneMesssage(int mid) {
		try {
			return msgDao.getOneMesssage(mid);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}finally{
			try {
				DBUtil.closeConn();
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		return null;
	}

	@Override
	public boolean addReply(Reply reply) {
		try {
			return msgDao.addReply(reply);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}finally{
			try {
				DBUtil.closeConn();
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		return false;
	}

	@Override
	public List<Reply> listReply(int mid) {
		try {
			return msgDao.listReply(mid);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}finally{
			try {
				DBUtil.closeConn();
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		return null;
	}

}
